<template>
  <!-- <IndexDef v-if="indexStyle === 0"></IndexDef>
  <IndexChart v-if="indexStyle === 1"></IndexChart>
  <IndexBdc v-if="indexStyle == 2"></IndexBdc> -->
  <IndexTask :newOrderData="newOrderData" :refundOrderData="refundOrderData" />

  <!-- <div style="width: 100%; text-align: right; margin-top: 20px">
    请选择首页样式：
    <a-radio-group v-model:value="indexStyle">
      <a-radio :value="0">默认1</a-radio>
      <a-radio :value="1">销量统计2</a-radio>
      <a-radio :value="2">业务统计3</a-radio>
      <a-radio :value="3">我的任务4</a-radio>
    </a-radio-group>
  </div> -->
</template>
<script setup>
import { unref, ref, onMounted, onUnmounted } from 'vue';
// import IndexDef from './homePage/IndexDef.vue';
// import IndexChart from './homePage/IndexChart.vue';
// import IndexBdc from './homePage/IndexBdc.vue';
import IndexTask from './homePage/IndexTask.vue';
import { getToken } from '/@/utils/auth';
import md5 from 'crypto-js/md5';
import { defHttp } from '/@/utils/http/axios';
import useEmitter from '/@/utils/use-emitter';
// import { useNurseStore } from '/@/store/modules/nurse';
import { useMessage } from '/@/hooks/web/useMessage';

const { notification } = useMessage();

// const nurseEmitter = useEmitter()

const newOrderData = ref([])

const refundOrderData = ref([])

async function getNewOrder() {
  newOrderData.value.length = 0
  const { records } = await defHttp.get({
    url: "/nurse_user_orders/nurseUserOrders/listAll",
    params: {
      pageNo: 1,
      pageSize: 10,
      status: '2'
    }
  })
  newOrderData.value = records
}
async function getRefundOrder() {
  refundOrderData.value.length = 0
  const { records } = await defHttp.get({
    url: "/nurse_user_orders/nurseUserOrders/listAll",
    params: {
      pageNo: 1,
      pageSize: 10,
      status: '8'
    }
  })
  refundOrderData.value = records
}

// nurseEmitter.$on('nurseEmitter-refresh-newOrder', async () => {
//   await getNewOrder()
//   if (newOrderData.value.length > 0) {
//     notification.warn({ message: "您有新的订单,请及时处理！", duration: 5 })
//     fetch("http://127.0.0.1:3007/newOrder")
//   }
// })

// nurseEmitter.$on('nurseEmitter-refresh-refundOrder', async () => {
//   await getRefundOrder()

//   if (refundOrderData.value.length > 0) {
//     getNewOrder()
//     notification.warn({ message: "您有新的退款申请,请及时处理！", duration: 5 })
//     fetch("http://127.0.0.1:3007/refundOrder")
//   }
// })

onMounted(() => {
  getNewOrder()
  getRefundOrder()
});

</script>
